﻿/*===============================================================================
	TASK 1b :                                           {Multidimentional Arrays}
	Write a program that fills and prints a matrix of size (n, n) as shown below:
    Example for n = 4
 
           1 8  9 16
           2 7 10 15 
           3 6 11 14
           4 5 12 13
================================================================================*/

using System;

class bMatrix
{
    static void Main()
    {
//=======================================================================
//                       FIRST SOLUTION
//=======================================================================
        int n = 5;
        int[,] matrix = new int[n, n];

        int counter;
        matrix[0, 0] = 1;

        for (int col = 0; col < n; col++)
        {
            if (matrix[0, col] % 2 == 0)
            {
                counter = -1;
            }
            else
            {
                counter = 1;
            }

            for (int row = 1; row < n; row++)
            {
                matrix[row, col] = matrix[row - 1, col] + counter;
            }

            if (col==n-1)
            {
                break;
            }
            matrix[0, col + 1] = matrix[n - 1, col] + n;
        }

        PrintQuadricMatrix(n, matrix);

//=======================================================================
//                       SECOND SOLUTION
//=======================================================================

    //    int[,] matrix1 = new int[n, n];
    //    for (int i = 0, counter1 = 1; i < n; i++) 
    //    {
    //        if (i % 2 == 0)
    //        {
    //            for (int j = 0; j < n; j++) 
    //            {
    //                matrix[j, i] = counter1++; 
    //            }
    //        }
    //        else 
    //        {
    //            for (int j = n - 1; j >= 0; j--) 
    //            {
    //                matrix[j, i] = counter1++;
    //            }  
    //        }
    //    }

    }

    private static void PrintQuadricMatrix(int n, int[,] matrix)
    {
        for (int row = 0; row < n; row++)
        {
            for (int col = 0; col < n; col++)
            {
                Console.Write(matrix[row, col] + " ");
            }
            Console.WriteLine();
        }
    }
}

